#ifndef OPTIONMODEL_H
#define OPTIONMODEL_H

#include <QAbstractItemModel>

#include "../common/other/gameStructs.h"
#include "collections/dualcollection.h"

class RosterUnit;

// \TODO: OptionModelItem should inherit yALB_AbstractTreeItem and OptionModel yALB_AbstractTreeModel

class OptionModelItem {
    friend class OptionModel;
public:
    OptionModelItem(OptionModelItem *_parent);
    ~OptionModelItem();

    QString key;

    OptionModelItem* parent() const;
    int childCount() const;
    OptionModelItem* child(int i) const;
    int row() const;

private:
    QVector<OptionModelItem*> children;
    OptionModelItem *parentItem;
};

class OptionModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    OptionModel(const DualCollection<GameCategory> *_categories, QObject *parent = 0);
    ~OptionModel();
    
    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const;
    QModelIndex parent(const QModelIndex &index) const;

    bool setData(const QModelIndex &index, const QVariant &value, int role);

    void forceOptionUpdate(const QString& key);
    void setSourceUnit(RosterUnit *unit);

signals:
    void optionCheckStateToChange(RosterUnit *unit, const QString& optionKey, Qt::CheckState targetState);

private:
    const DualCollection<GameCategory> *categories;
    RosterUnit *currentUnit;

    OptionModelItem *rootItem;
};

#endif // OPTIONMODEL_H
